package com.zzk.lanouhn.myapplication1.adapters;

import android.content.Context;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;

import com.squareup.picasso.Picasso;
import com.zzk.lanouhn.myapplication1.R;
import com.zzk.lanouhn.myapplication1.modles.InvestPingLunAuthorPhotoModle;

/**
 * Created by lanouhn on 16/9/19.
 */
public class InvestPinglunAuthorPhotoDaAdapter extends RecyclerView.Adapter<InvestPinglunAuthorPhotoDaAdapter.PhotoDaHorld> {
    private Context context;
    private InvestPingLunAuthorPhotoModle photoModle;

    public InvestPinglunAuthorPhotoDaAdapter(Context context, InvestPingLunAuthorPhotoModle photoModle) {
        this.context = context;
        this.photoModle = photoModle;
    }

    @Override
    public PhotoDaHorld onCreateViewHolder(ViewGroup parent, int viewType) {
        //绑定item的布局
        View view = LayoutInflater.from(context).inflate(R.layout.item_pinglun_author_photo_da, null);
        PhotoDaHorld horld = new PhotoDaHorld(view);
        return horld;
    }

    @Override
    public void onBindViewHolder(PhotoDaHorld holder, int position) {
        if (photoModle.getData() == null) {

        } else {
            //使用第三方解析图片
            Picasso.with(context).load(photoModle.getData().get(position).getPic_url()).into(holder.iv_da_tu);
            //如果有文字，解析如下
            // holder.控件名.setText(photoModle.getData().get(position).getPic_url());
        }

    }

    @Override
    public int getItemCount() {
        return photoModle.getData().size();
    }

    public class PhotoDaHorld extends RecyclerView.ViewHolder {
        //item布局里的控件
        private ImageView iv_da_tu;

        public PhotoDaHorld(View itemView) {
            super(itemView);
            iv_da_tu = (ImageView) itemView.findViewById(R.id.photo_da_iv);
        }
    }
}
